﻿/*
 HoverTreeCMS
 *
 */
namespace HoverTree.HoverTreeFrame.WebUI
{
    public class KeleyiPager
    {
        public static string BuildPageIndex(int pageIndex, int totalPageCount)
        {
            return BuildPageIndex(pageIndex, totalPageCount, string.Empty);
        }
        public static string BuildPageIndex(int pageIndex, int totalPageCount, string moreParams)
        { return BuildPageIndex(pageIndex, totalPageCount, moreParams, string.Empty); }

        public static string BuildPageIndex(int pageIndex, int totalPageCount, string moreParams, string absoluteAddress)
        {
            if (pageIndex > totalPageCount) pageIndex = totalPageCount;
            if (pageIndex < 1) pageIndex = 1;

            string m_pageIndexInfo = pageIndex.ToString() + "/" + totalPageCount.ToString();

            if (moreParams != string.Empty)
                moreParams = "&" + moreParams;

            if (pageIndex > 2)
                m_pageIndexInfo = "<a href=\"" + absoluteAddress + "?pi=1" + moreParams + "\">第一页</a> <a href=\"" + absoluteAddress + "?pi=" + (pageIndex - 1).ToString() + "" + moreParams + "\">上一页</a> " + m_pageIndexInfo;
            else if (pageIndex == 2)
                m_pageIndexInfo = "<a href=\"" + absoluteAddress + "?pi=1" + moreParams + "\">第一页</a> " + m_pageIndexInfo;

            if (pageIndex == totalPageCount - 1)
                m_pageIndexInfo = m_pageIndexInfo + " <a href=\"" + absoluteAddress + "?pi=" + totalPageCount.ToString() + moreParams + "\">末页</a>";
            else if (pageIndex < totalPageCount - 1)
                m_pageIndexInfo = m_pageIndexInfo + " <a href=\"" + absoluteAddress + "?pi=" + (pageIndex + 1).ToString() + moreParams + "\">下一页</a> " + "<a href=\"" + absoluteAddress + "?pi=" + totalPageCount.ToString() + moreParams + "\">末页</a> ";

            return m_pageIndexInfo;
        }
    }
}